<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/add.css"/>
	</head>
	<body>
		<div id="app">
			<div class="header">
				<span>修改快递员</span>
			</div>
			<div class="content">
				<table>	
					<tr>
						<td class="text-right">手机号码</td><td class="content_right"><input class="input inline-input" placeholder="请输入手机号码" id="phone"> <span class="btn btn-info" id="find">立即查找</span></td>
					</tr>
				</table>
			</div>
			
			
			<div class="header">
				<span>查找信息如下</span>
			</div>
			<div class="content">
				<table>
					<tr>
						<td class="text-right">姓名</td><td class="content_right"><input class="input" placeholder="请输入姓名"></td>
					</tr>
					<tr>
						<td class="text-right">手机号码</td><td class="content_right"><input class="input" placeholder="请输入手机号码"></td>
					</tr>
					<tr>
						<td class="text-right">身份证号码</td><td class="content_right"><input class="input" placeholder="请输入身份证号码"></td>
					</tr>
					<tr>
						<td class="text-right">密码</td><td class="content_right"><input class="input" placeholder="请输入密码"></td>
					</tr>
					<tr>
						<td></td><td class="content_right"><span class="btn btn-info" id="update">立即修改</span> <span class="btn">重置</span> </td>
					</tr>
				</table>
			</div>
		</div>

		<script src="/qrcode/jquery2.1.4.js"></script>
		<script src="/layer/layer.js"></script>
		<script>
			$(".header:eq(1),.content:eq(1)").hide();//查询前，先隐藏展示查询结果的table
			var courierId=null; //定义全局变量:快递员id，修改时需要使用
			$(function () {
				$("#find").click(function () { //绑定点击事件
					var windowId = layer.load();//加载的弹出层效果
					var phone = $("#phone").val();//获取输入表单的手机号
					$.getJSON("/courier/find.do",{phone:phone},function (data) {//发送ajax请求到服务器
						//{"status":0,"result":"查询成功","data":{"id":10,"number":"123123123","username":"李四","userPhone":"123456789","company":"顺丰快递","code":"819821","inTime":"Apr 2, 2021, 12:38:47 AM","status":0,"sysPhone":"123456789"}}
						layer.close(windowId);//关闭加载层
						layer.msg(data.result);//显示执行结果
						if (data.status==0){ //成功
							$(".header:eq(1),.content:eq(1)").fadeIn(2000);//将展示查询结果的table淡入出来
							courierId=data.data.id; //获取通过手机查询到的快件的id，过会根据id去更新
							$("input:eq(1)").val(data.data.username); //根据查询的快递填充到table表单中
							$("input:eq(2)").val(data.data.phone);
							$("input:eq(3)").val(data.data.cardId);
							$("input:eq(4)").val(data.data.password);
						}
					});
				});

				$("#update").click(function(){
					var windowId = layer.load();//加载效果
					var username = $("input:eq(1)").val();//先获取表单数据
					var phone = $("input:eq(2)").val();
					var cardId = $("input:eq(3)").val();
					var password = $("input:eq(4)").val();

					var user = {   //将参数封装到对象发送到服务器
						id:courierId,
						username:username,
						phone:phone,
						cardId:cardId,
						password:password
					};
					$.getJSON("/courier/update.do",user,function(data){
						layer.close(windowId);
						layer.msg(data.result)

						if(data.status == 0){
							//修改成功的，隐藏
							$(".header:eq(1),.content:eq(1)").hide();
						}
					})
				});
			});
		</script>
	</body>
</html>
